<template>
  <!-- 资源清单 -->
  <div id="resourceInfo">
    <div class="gcontent" v-if="applyinfo.resourcesInfo.resourceInfo.length > 0" style="padding-bottom:10px;">
      <template>
        <Form :label-width="labelWidth" label-position="left" class="form form_left">
          <div v-show="ifedit && tempResource != undefined && tempResource.length > 0 " v-for="(item, index) in tempResource">
            <CheckboxGroup v-model="applyinfo.resourcesInfo.resourceChcekList">
              <Row>
                <Col span="12">
                <Checkbox class="font_seize" v-bind:label="item.resourceName" :disabled="ifedit">
                  <!-- {{item.resourceName}} -->
                  {{item.resourceName.split(".").length > 1 ? item.resourceName.split(".")[1]:item.resourceName}}
                </Checkbox>

                </Col>
              </Row>
            </CheckboxGroup>
            <div style="padding-top: 8px;width: 97%;">
              <template v-for="(i,index) in applyinfo.resourcesInfo.resourceChcekList">
                <div v-if="item.resourceName === i && 'severs' != i">
                  <resourceTable :ifedit="ifedit" :type="'enty_resource'" :key="index" v-model="item.list" :columnsList="resourcesInfo.columns"></resourceTable>
                </div>
              </template>
            </div>
            <div style="height: 30px;"></div>
          </div>
          <div v-show="(isEdit != 1 && ifedit)|| !ifedit && (applyinfo.resourcesInfo.resourceInfo.length > 0 )" v-for="(item, index) in applyinfo.resourcesInfo.resourceInfo">
            <CheckboxGroup v-model="applyinfo.resourcesInfo.resourceChcekList">
              <Checkbox class="font_seize" v-bind:label="item.resourceName" :disabled="ifedit">
                <!-- {{item.resourceName}} -->
                {{item.resourceName.split(".").length > 1 ? item.resourceName.split(".")[1]:item.resourceName}}
              </Checkbox>
            </CheckboxGroup>
            <div style="padding-top: 8px;padding-left:8px;width: 97%;">
              <template v-for="(i,index) in applyinfo.resourcesInfo.resourceChcekList">
                <div v-if="item.resourceName === i && 'severs' != i">
                  <resourceTable :ifedit="ifedit" :type="'enty_resource'" :key="index" v-model="item.list" :columnsList="resourcesInfo.columns"></resourceTable>
                </div>
              </template>
            </div>
            <div style="height: 30px;"></div>
          </div>
        </Form>
      </template>
    </div>
    <template v-else>
      <div class="gcontent" style="text-align:center">
        <span style="font-size: 13px;margin-left: 15px;color:#bbb; ">暂无申请资源</span>
      </div>
    </template>
  </div>
</template>
<script>
  import ajax from "../../../ajax_util"
  import Axios from 'axios'
  import resourceTable from "../../../base/tables"

  export default {
    name: "apply",
    components: {
      resourceTable
    },
    data() {
      const validateEntryEndTime = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请选择结束时间'));
        } else {
          if (this.applyinfo.projectInfo.entryStartTime === '') {
            callback(new Error('请选择开始时间'));
          } else if (this.applyinfo.projectInfo.entryStartTime.getTime() > value.getTime()) {
            callback(new Error('结束时间不能小于开始时间'));
          } else {
            callback()
          }
        }
      };

      return {
        readonly: true, //是否只读
        labelWidth: 140,
        bealoonTrue: true,
        name: "",
        //资源清单相关基础信息
        resourcesInfo: this.Presources,
        applyinfo: this.Papply
      }
    },
    created: function() {
      console.log(this.PresourcesInfo)
    },
    mounted: function() {

    },
    computed: {
    },
    methods: {
      //校验资源申请表单
      validate() {
        var b = false
        var temp = this.applyinfo
        var chack = temp.resourcesInfo.resourceChcekList
        var resourceList = temp.resourcesInfo.resourceInfo
        chack.forEach(key => {
          if (key != "severs") {
            resourceList.some(item => {
              if (key === item.resourceName) {
                item.list.some(list => {
                  // if(list.val != undefined && list.val != null ){
                  console.log("list.check-------->", list.check)
                  if (list.check) {
                    if (list.resourcetype == 0 || list.resourcetype == 5 || list.resourcetype == 6) {
                      var t = this.validefault(list)
                      if (t) {
                        b = true
                        return t
                      }
                    } else {
                      if (list.val != null && list.val != '') {
                        if (list.purpose == undefined || list.purpose == '') {
                          console.log(list.val, list.purpose)
                          this.$Message.warning({
                            content: "请选择“申请资源清单—>" + item.resourceName + "—>" + list.serviceName +
                              "—>" + list.subName + "”的测算依据",
                            duration: 3
                          })
                          b = true
                          return true
                        }
                      } else {
                        this.$Message.warning({
                          content: "请选择或填写“申请资源清单—>" + item.resourceName + "—>" + list.serviceName +
                            "—>" + list.subName + "”的可选项",
                          duration: 3
                        })
                        b = true
                        return true
                      }
                    }
                  }
                  // }
                })
                return true
              }
            })
          }
        });
        console.log("b->", b)
        return b;
      },
      //校验默认
      validefault(data) {
        console.log("data--->", data)
        var temp = false
        if(data.val == undefined || data.val == null || data.val == ''){
            data.val = 0
        }
        if (data.unit === undefined || data.unit === null || data.unit === '') {
          this.$Message.warning({
            content: "请选择“申请资源清单—>" + data.clazz + "—>" + data.serviceName + "—>" + data.subName + "”的单位",
            duration: 3
          })
          temp = true
        } else if (data.purpose == undefined || data.purpose ==null ||  data.purpose == '') {
          this.$Message.warning({
            content: "请选择“申请资源清单—>" + data.clazz + "—>" + data.serviceName + "—>" + data.subName + "”的测算依据",
            duration: 3
          })
          temp = true
        }
        // }else{
        //   this.$Message.warning({
        //           content: "请选择“申请资源清单—>" + data.clazz + "—>" + data.serviceName + "—>" + data.subName + "”的数量",
        //           duration: 3
        //       })
        //   temp = true
        // }

        return temp
      }
    },
    props: {
      isEdit:{},
      ifedit: {},
      Papply: {},
      Presources: {},
      tempTool: {},
      tempResource: {}
    },

  }
</script>
